package com.example.red_tea_house.moudle.Home.controller;

import android.util.Log;

import com.example.red_tea_house.annotation.ArticleType;
import com.example.red_tea_house.annotation.UrlType;
import com.example.red_tea_house.entity.StoryBean;
import com.google.gson.Gson;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import org.litepal.LitePal;


import okhttp3.Call;

public class getAndSetStoryController {
    private StoryBean story=new StoryBean();

    public void saveStoryFromRemote(){
        OkHttpUtils
                .get()
                .url(UrlType.REMOTESERVER_URL +UrlType.GETRANDOM_STORY)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {

                    }

                    @Override
                    public void onResponse(String response, int id) {
                        story=new Gson().fromJson(response, StoryBean.class);
                        story.save();
                    }
                });
    }

    public void clearOldRemoteStory(){
        LitePal.deleteAll(StoryBean.class,"tag=?",  "2");
    }
}
